package dao;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import persistencia.HibernateUtil;

public class HibernateDAO {
	private static HibernateDAO instance;
	private static SessionFactory sf;
	private static Session session;

	public static HibernateDAO getInstance() {
		if (instance == null)
			instance = new HibernateDAO();
		return instance;
	}

	private HibernateDAO() {
		sf = HibernateUtil.getSessionFactory();
	}

	public Session getSession() {
		if (session == null || !session.isOpen())
			session = sf.openSession();
		return session;
	}

	public void closeSession() {
		if (session != null) {
			session.close();
			session = null;
		}
	}
}